package com.cpa.admin.controller;

import com.cpa.admin.config.BaseController;
import com.cpa.admin.service.UserOrderService;
import com.cpa.admin.vo.StatisticsMonthOrderVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author zhen.zhao01
 * @CreateDate 2018/10/31
 */
@Controller
@RequestMapping("welcome")
public class WelcomeController extends BaseController {

    private final UserOrderService userOrderService;

    @Autowired
    public WelcomeController(UserOrderService userOrderService) {
        this.userOrderService = userOrderService;
    }


    @GetMapping
    public String welcome() {
        return "welcome";
    }




    @ResponseBody
    @GetMapping("statistics")
    public Map<String, List> statistics() {

        List<StatisticsMonthOrderVo> statisticsMonthOrderVoList = userOrderService.statisticsMonthOrderVo();
        List<String> days = new ArrayList<>(statisticsMonthOrderVoList.size());
        List<Integer> count = new ArrayList<>(statisticsMonthOrderVoList.size());

        statisticsMonthOrderVoList.stream().forEach(s -> {
            days.add(s.getDay());
            count.add(s.getCount());
        });

        Map<String, List> map = new HashMap<>();
        map.put("days", days);
        map.put("count", count);

        return map;
    }

}
